// CODEMIRROR STYLING

// Don't use text cursor on the scrollbar
.CodeMirror-vscrollbar { cursor: default; }

.CodeMirror {
  // The textarea element needs to have the same
  // font-size as the editor, even though it is
  // hidden. This way, pop-ups for non-western
  // fonts such as Hiragana/Katakana are correctly
  // aligned. Should also help accessibility-plugins.
  &.CodeMirror-wrap > div:first-child {
    textarea {
      font-family: inherit;
      font-size: inherit;
      line-height: inherit;
      height: 1.4375em !important;
      bottom: -1.4375em !important;
      transform: scaleY(1.1);
    }
  }

  font-size: 1em;
  line-height: 1.4375;
  user-select: text;
  // margin-bottom: -@tabbar-height; // I hate myself for this
  background-color: inherit; // Override the codemirror.css default

  // This directive prevents strange colour artifacts when a document is open
  // that has less lines of code than fit into the window (especially notable
  // in dark mode, as the sizer is visible with a small green halo).
  .CodeMirror-sizer { height: 100%; }

  &.CodeMirror-empty {
    background-position: center center;
    background-size: contain;
    background-repeat: no-repeat;
    // In the editor.less, we've defined 5em top margin on the code element
    // which it not present in an empty editor. Therefore, we need to apply
    // it to the whole content in case of an empty editor.
    padding-top: 5em;
  }

  &.CodeMirror-empty.CodeMirror-readonly {
    // If the editor is empty, display a nice background image
    background-image: url('../../img/logo.svg');
  }

  pre { padding: 0; }

  input[type="checkbox"] {
    transform: scale(1.2);
    margin: 0.2em;
    vertical-align: middle;
  }

  .search-result {
    background-color: yellow !important;
    color: black !important;
    border-radius: 0px !important;
    padding-right: 0px !important;
  }

  .cm-table {
    font-family: @font-code;
    font-weight: bold;
  }

  .size-header-1 {
    font-size: 2em;
    .CodeMirror-gutter-elt { line-height: 1.5em; }
  }
  .size-header-2 {
    font-size: 1.8em;
    .CodeMirror-gutter-elt { line-height: 1.5em; }
  }
  .size-header-3 {
    font-size: 1.5em;
    .CodeMirror-gutter-elt { line-height: 1.4em; }
  }
  .size-header-4 {
    font-size: 1.3em;
    .CodeMirror-gutter-elt { line-height: 1.3em; }
  }
  .size-header-5 { font-size: 1em; }
  .size-header-6 { font-size: 1em; }

  .cm-comment,
  .cm-formatting-task,
  .cm-fenced-code { font-family: @font-code; }

  .CodeMirror-cursor {
    width: 2px;
    border: 0;
    z-index: 1;
    transform: translateZ(0);
    animation: soft-blink @cursor-blink-rate infinite; // Use the "soft-blink" animation
  }

  /* Implement a "fat" cursor for Windows' overwrite mode (Ins key) */
  // Also valid for vim and everything that needs a block cursor.
  .CodeMirror-overwrite .CodeMirror-cursor, &.cm-fat-cursor .CodeMirror-cursor {
    width: auto;
    border-top: 2px solid #333;
    border-bottom: 2px solid #333;
    background-color: rgba(0, 0, 0, 0.25);
  }

  /* Make the formatting characters and escape sequences nearly invisible */
  .cm-formatting-code,
  .cm-formatting-code-block,
  .cm-formatting-quote,
  .cm-formatting-strong,
  .cm-formatting-em,
  .cm-zkn-link-formatting,
  .cm-escape-char { opacity: 0.3; }

  .cm-formatting-quote,
  .cm-formatting-list-ul,
  .cm-formatting-list-ol {
    font-family: @font-code;
  }

  #measureWidth {
    position: absolute;
    visibility: hidden;
    height: auto;
    width: auto;
    white-space: nowrap;
  }

  #measureMonoWidth {
    font-family: @font-code;
    position: absolute;
    visibility: hidden;
    height: auto;
    width: auto;
    white-space: nowrap;
  }

  .cm-tab {
    display: inline;
  }

  .cm-url, .cm-link { text-decoration: none; }

  // Meta-key adaptions
  .cm-zkn-tag.meta-key, .cm-zkn-link.meta-key, .cma.meta-key { cursor: pointer; }
  .cm-zkn-tag.meta-key:hover,
  .cm-zkn-link.meta-key:hover,
  a.cma { text-decoration: underline; }

  .cm-zkn-tag { font-weight: bold; }

  // Text-folding related stuff
  .CodeMirror-gutters {
    background-color: transparent;
    border: none;
    width: 2em;
    padding-right: 10px;
  }
  .CodeMirror-foldgutter {
    width: 2em;
  }
  .CodeMirror-foldgutter-open, .CodeMirror-foldgutter-folded {
    text-align: right;
    cursor: pointer;
    font-size: 18px;

    &:hover {
      color: var(--c-primary);
    }
  }
  .CodeMirror-foldgutter-open:after { content: "\25BE"; }
  .CodeMirror-foldgutter-folded:after { content: "\25B8"; }

  .CodeMirror-foldmarker {
    border-radius: @border-radius;
    display: inline-block;
    font-size: 75%;
    margin-left: 10px;
    padding: 2px;
    cursor: pointer;
    vertical-align: baseline;
  }
}

.heading-tag {
  display: inline-block;
  cursor: pointer;
  border-radius: @border-radius;
  padding: 0 4px;

  span {
    font-size: 20px;
    font-weight: normal;
  }
}

// Hints (tag autocompletion, etc.)
.CodeMirror-hints {
  position: absolute;
  z-index: 10;
  overflow: hidden;
  list-style: none;

  margin: 0;
  padding: 0px;

  max-height: 20em;
  overflow-y: auto;
  li.CodeMirror-hint {
    margin: 0;
    white-space: pre;
    cursor: pointer;
    padding: 5px;
    line-height: 150%;
  }

  // Apply a bolder font weight to tags that have a specific colour assigned.
  .cm-hint-colour { font-weight: bold; }
}
